package com.cs496.finalproject;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;
//This class contains all the mthods and attributes of the objects we are storing in
//The Google database. 
@PersistenceCapable
public class Item {
	
	@PrimaryKey 
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	
	@Persistent
	private float val1;
	
	@Persistent
	private float val2;
	
	@Persistent
	private float val3;
	
	@Persistent
	private String caption;
	
	@Persistent
	private static int count;
	
	@Persistent
	private Blob photo;
	
	@Persistent
	private int voteCount;
	
	@Persistent
	private Long createdAt;
	
	@Persistent
	private String date;;

	
	public Item(){		
		++count;
		long current = System.currentTimeMillis();
		setCreatedAt(current);
		date = setDate(current);
		
	}
	
	public Item(float a, float b, float c)
	{
		val1 = a;
		val2 = b;
		val3 = c;
	}
	
	public float setVal1(int a){
		
		float b;
		b = a;
		return b;
	}
	
	public float setVal2(int a){
		
		float b;
		b = a;
		return b;
	}
	
	public float setVal3(int a){
		
		float b;
		b = a;
		return b;
	}
	
	
	public Item(Long id, byte[] photo )
	{
		
		long current = System.currentTimeMillis();
		setCreatedAt(current);
		setDate(current);
		
	}
	
	public Long getCreatedAt() {
		return createdAt;
	}
	
	public float getVal1()
	{
		return val1;
	}
	
	public float getVal2()
	{
		return val2;
	}
	
	public float getVal3()
	{
		return val3;
	}
	
	public int getCount()
	{ return count;}
	
	public Long getid()
	{
		return id;	
	}
	
	public int incVote()
	{
		++voteCount;
		return this.voteCount;
	}
	
	public int decVote()
	{
		voteCount--;
		return voteCount;
	}
	
	public int getVote()
	{
		return voteCount;
	}
	
	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}
	public byte[] getPhoto(){
		return photo != null ? photo.getBytes(): new byte[0];
	}
	
	public void setPhoto(byte[] photo) {
        this.photo = new Blob(photo != null ? photo : new byte[0]);
    }
	
	public void setCreatedAt(Long createdAt) {
		this.createdAt = createdAt;
	}
	
	public String setDate(long date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");

        Date resultdate = new Date(date);
        
        return sdf.format(resultdate);
		
	}

	public String getDate()
	{
		return date;
		
	}
	
	
	
	
}
	
	
	
	
	

